<?php
/*
 * This file is part of PHP CS Fixer.
 * (c) xieyuhua <1510120461@qq.com>
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace app\index\Controller;
use think\Db;

class PriceAction extends BaseAction {

    public function _initialize() {
        parent::_initialize();
    }


    public  function push($a, $b) {
        $t1 = microtime(true);
        $db = Db::connect("swoole");
        $busnos = $db->name('o2o_jddj_goods')->field("skuname,outskuid")->order("fixeddowntime asc")->select();
       
       
        
        $t2 = microtime(true);
        echo  $this->toColor('耗时'.round($t2-$t1,3).'秒'.PHP_EOL.PHP_EOL.PHP_EOL);
    }
    
    
    /**
     * 模拟POST数据包
     * @param unknown $voteurl
     * @param unknown $data
     * @return mixed  */
    public function pushpost($voteurl, $data) {
        $ch = curl_init ();
        curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt ($ch, CURLOPT_URL, $voteurl);
        // 要访问的地址
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 60);
        // 超时断开时间
        curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
        // POST的数据
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
        // 是否接收返回数据
        $result = curl_exec ($ch);
        // 执行POST并把结果赋值给变量
        return $result;
        // 显示执行结果
    }


    //颜色
    public function toColor($in) {
        if (is_numeric($in)) {
            $r = ($in > -1)?"\033[31m{$in}\033[0m":$in;
        } else {
            $r = "\033[31m{$in}\033[0m";
        }
        return $r;
    }
    
    
    //内存计算
    public function memory_usage() {
        $memory = (! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024, 2).'KB';
        return $memory;
    }

}